﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoyoEden.Models;
using System.IO;
using System.Web.UI;

namespace CoyoEden.Web.Controls
{
	public class CommunityViewBase:ViewBase
	{
		#region Properties
		
		/// <summary>
		/// The Community for the view
		/// </summary>
		public Community TheCommunity
		{
			get;
			set;
		}
		/// <summary>
		/// Topics showing in the view.
		/// </summary>
		public List<Topic> TopicsShow { get; set; }
		#endregion

		#region Readonly Properties
		/// <summary>
		/// Current community's absolute Url.Readonly
		/// </summary>
		public string Url {
			get {
				var url = Utils.AbsoluteWebRoot + "community/" + TheCommunity.Id.ToString()+".aspx";
				return url;
			}
		}
		/// <summary>
		/// Current Community topics.Readonly
		/// </summary>
		public List<Topic> Topics {
			get {
				return Topic.GetTopicsByCommunity(TheCommunity.Id);
			}
		}
		/// <summary>
		/// Today's topics.Readonly
		/// </summary>
		public List<Topic> ToDayTopics {
			get {
				return Topics.FindAll(t=>t.DateCreated.Date==DateTime.Now.Date);
			}
		}
		#endregion

		#region Methods
		/// <summary>
		/// get current community's New topics.
		/// </summary>
		/// <param name="num"></param>
		/// <returns></returns>
		public List<Topic> NewTopics(int num) {
			return Topics.OrderByDescending(t => t.DateCreated).Take(num).ToList();
		}
		#endregion
	}
}
